home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-05-22 | 2.3 KB | 83 lines | [TEXT/CWIE] |
- // =================================================================================
- // PL_Utils.cp 1997 BB's Team inc. All rights reserved.
- // =================================================================================
- #include <UTextTraits.h>
-
- class PL_Utils {
-
- friend class PL_Utils_Init;
-
- public:
- static Handle ForceNewHandle (Handle &, Int32);
- static void CenterRect ( Rect *, const Rect &);
- static void FitRect ( Rect *, const Rect &);
- static int CountBits ( unsigned char);
- static void PlayNamedSound ( Str255);
-
- static void ComputeBBox (TextTraitsRecord &, Int32 inSize, Int32 &outWidth,
- Int32 &outHeight, Int32 &outAscent);
- static Boolean IsMonoSpace (Str255 fontName);
- static Int16 RepeatCharWidth(unsigned char = 0);
-
- private:
- static unsigned char sBaseWidthChar;
- static unsigned char sVersusWidthChar;
- static unsigned char sWidthRepeat;
- static unsigned char sMonoTestSize;
- static void Initialize (void);
- };
-
-
- // ---------------------------------------------------------------------------------
- // • abs
- // ---------------------------------------------------------------------------------
- template <class T> T abs (const T& in)
- {
- if (in < 0)
- return -in;
- else
- return in;
- }
-
-
- // ---------------------------------------------------------------------------------
- // • ShellSort
- // ---------------------------------------------------------------------------------
- template <class T>
- void ShellSort (T* array, int n, Boolean (*compare) (const T&, const T&) )
- {
- int i, j, h;
- T val;
-
- /* Serie quasi-optimale : 1, 4, 13, 40, 121, 364... */
- for (h=1 ; h<n/9 ; h=3*h+1)
- {} ;
-
- /* Increments successifs des series */
- for ( ; h>0 ; h/=3 )
-
- /* Tri de chaque h-serie */
- for ( i=h ; i<n ; i++ ) {
- val = array[j=i];
- while ( j>=h && (*compare)(array[j-h],val) ) {
- array[j] = array[j-h];
- j -= h;
- }
- array[j] = val;
- }
- }
-
- // ---------------------------------------------------------------------------------
- // • PL_Utils_Init
- // ---------------------------------------------------------------------------------
- // Library initialisation, The C++ Langage, B. Stroustrup (p.356 in the French edition)
- class PL_Utils_Init {
- public :
- PL_Utils_Init() { if (count++==0) PL_Utils::Initialize(); }
- ~PL_Utils_Init() { }
- private :
- static int count;
- };
-
- static PL_Utils_Init aPL_Utils_Init;
-